package httpserver.request;

import httpserver.HTTPException;
import httpserver.general.HTTPMethods;
import httpserver.general.HTTPStatusCodes;
import java.net.URLDecoder;

public class StartingLine{

    private String method;
    private String uri;
    private int minorVersion;
    private int majorVersion;

    StartingLine(String method, String uri, int major, int minor)
            throws HTTPException {
        if(!HTTPMethods.hasMethod(method)){
            throw new HTTPException(HTTPStatusCodes.HTTP_BAD_REQUEST);
        }
        this.method = method;
        this.uri = uri;
        minorVersion = minor;
        majorVersion = major;
    }
    
    public int getMinorVersion(){
        return minorVersion;
    }
    public int getMajorVersion(){
        return majorVersion;
    }
    public String getMethod() {
        return method;
    }
    public String getURI() {
        try{
            return URLDecoder.decode(uri, "UTF-8");
        } catch (Exception e) {
            return uri;
        }
    }

}
